1 /*
2  * This file is part of gtkD.
3  *
4  * gtkD is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU Lesser General Public License
6  * as published by the Free Software Foundation; either version 3
7  * of the License, or (at your option) any later version, with
8  * some exceptions, please read the COPYING file.
9  *
10  * gtkD is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public License
16  * along with gtkD; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA
18  */
19 
20 // generated automatically - do not change
21 // find conversion definition on APILookup.txt
22 // implement new conversion functionalities on the wrap.utils pakage
23 
24 
25 module gtk.MapListModel;
26 
27 private import gio.ListModelIF;
28 private import gio.ListModelT;
29 private import glib.ConstructionException;
30 private import gobject.ObjectG;
31 private import gtk.c.functions;
32 public  import gtk.c.types;
33 
34 
35 /**
36  * A `GtkMapListModel` maps the items in a list model to different items.
37  * 
38  * `GtkMapListModel` uses a [callback@Gtk.MapListModelMapFunc].
39  * 
40  * Example: Create a list of `GtkEventControllers`
41  * ```c
42  * static gpointer
43  * map_to_controllers (gpointer widget,
44  * gpointer data)
45  * {
46  * gpointer result = gtk_widget_observe_controllers (widget);
47  * g_object_unref (widget);
48  * return result;
49  * }
50  * 
51  * widgets = gtk_widget_observe_children (widget);
52  * 
53  * controllers = gtk_map_list_model_new (widgets,
54  * map_to_controllers,
55  * NULL, NULL);
56  * 
57  * model = gtk_flatten_list_model_new (GTK_TYPE_EVENT_CONTROLLER,
58  * controllers);
59  * ```
60  * 
61  * `GtkMapListModel` will attempt to discard the mapped objects as soon as
62  * they are no longer needed and recreate them if necessary.
63  */
64 public class MapListModel : ObjectG, ListModelIF
65 {
66 	/** the main Gtk struct */
67 	protected GtkMapListModel* gtkMapListModel;
68 
69 	/** Get the main Gtk struct */
70 	public GtkMapListModel* getMapListModelStruct(bool transferOwnership = false)
71 	{
72 		if (transferOwnership)
73 			ownedRef = false;
74 		return gtkMapListModel;
75 	}
76 
77 	/** the main Gtk struct as a void* */
78 	protected override void* getStruct()
79 	{
80 		return cast(void*)gtkMapListModel;
81 	}
82 
83 	/**
84 	 * Sets our main struct and passes it to the parent class.
85 	 */
86 	public this (GtkMapListModel* gtkMapListModel, bool ownedRef = false)
87 	{
88 		this.gtkMapListModel = gtkMapListModel;
89 		super(cast(GObject*)gtkMapListModel, ownedRef);
90 	}
91 
92 	// add the ListModel capabilities
93 	mixin ListModelT!(GtkMapListModel);
94 
95 
96 	/** */
97 	public static GType getType()
98 	{
99 		return gtk_map_list_model_get_type();
100 	}
101 
102 	/**
103 	 * Creates a new `GtkMapListModel` for the given arguments.
104 	 *
105 	 * Params:
106 	 *     model = The model to map
107 	 *     mapFunc = map function
108 	 *     userData = user data passed to @map_func
109 	 *     userDestroy = destroy notifier for @user_data
110 	 *
111 	 * Returns: a new `GtkMapListModel`
112 	 *
113 	 * Throws: ConstructionException GTK+ fails to create the object.
114 	 */
115 	public this(ListModelIF model, GtkMapListModelMapFunc mapFunc, void* userData, GDestroyNotify userDestroy)
116 	{
117 		auto __p = gtk_map_list_model_new((model is null) ? null : model.getListModelStruct(), mapFunc, userData, userDestroy);
118 
119 		if(__p is null)
120 		{
121 			throw new ConstructionException("null returned by new");
122 		}
123 
124 		this(cast(GtkMapListModel*) __p, true);
125 	}
126 
127 	/**
128 	 * Gets the model that is currently being mapped or %NULL if none.
129 	 *
130 	 * Returns: The model that gets mapped
131 	 */
132 	public ListModelIF getModel()
133 	{
134 		auto __p = gtk_map_list_model_get_model(gtkMapListModel);
135 
136 		if(__p is null)
137 		{
138 			return null;
139 		}
140 
141 		return ObjectG.getDObject!(ListModelIF)(cast(GListModel*) __p);
142 	}
143 
144 	/**
145 	 * Checks if a map function is currently set on @self.
146 	 *
147 	 * Returns: %TRUE if a map function is set
148 	 */
149 	public bool hasMap()
150 	{
151 		return gtk_map_list_model_has_map(gtkMapListModel) != 0;
152 	}
153 
154 	/**
155 	 * Sets the function used to map items.
156 	 *
157 	 * The function will be called whenever an item needs to be mapped
158 	 * and must return the item to use for the given input item.
159 	 *
160 	 * Note that `GtkMapListModel` may call this function multiple times
161 	 * on the same item, because it may delete items it doesn't need anymore.
162 	 *
163 	 * GTK makes no effort to ensure that @map_func conforms to the item type
164 	 * of @self. It assumes that the caller knows what they are doing and the map
165 	 * function returns items of the appropriate type.
166 	 *
167 	 * Params:
168 	 *     mapFunc = map function
169 	 *     userData = user data passed to @map_func
170 	 *     userDestroy = destroy notifier for @user_data
171 	 */
172 	public void setMapFunc(GtkMapListModelMapFunc mapFunc, void* userData, GDestroyNotify userDestroy)
173 	{
174 		gtk_map_list_model_set_map_func(gtkMapListModel, mapFunc, userData, userDestroy);
175 	}
176 
177 	/**
178 	 * Sets the model to be mapped.
179 	 *
180 	 * GTK makes no effort to ensure that @model conforms to the item type
181 	 * expected by the map function. It assumes that the caller knows what
182 	 * they are doing and have set up an appropriate map function.
183 	 *
184 	 * Params:
185 	 *     model = The model to be mapped
186 	 */
187 	public void setModel(ListModelIF model)
188 	{
189 		gtk_map_list_model_set_model(gtkMapListModel, (model is null) ? null : model.getListModelStruct());
190 	}
191 }